package com.itHsuSE.demo9;

import java.io.*;

/**
 * @author Hsu琛君珩
 * @ClassName:Test3
 * @date 2023-12-20
 * @apiNote
 * @Version: v1.0
 */

public class Test3 {
    public static void main(String[] args) throws IOException {
        String str = "你好啊";
        //将str转为字节数组，编码为UTF8
        //一个英文字符对应一个字节，一个中文字符对应2到3个字节
        byte[] bytes = str.getBytes("UTF-8");

        File file = new File("test3.txt");
        OutputStream out = new FileOutputStream(file);
        out.write(bytes);
        out.close();

        //System.out.println("成功：n="+n);
    }
}
